package com.gmall.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig_WorkQueue {

    public static final String Exchange_Direct_2109A = "Exchange_Direct_2109A";

    public static final String Queue_Work = "Queue_Work";

    public static final String ROUTING_KEY = "Queue_Work";

    @Bean(Exchange_Direct_2109A)
    public Exchange Exchange_Direct_2109A(){
        return ExchangeBuilder
                .directExchange(Exchange_Direct_2109A)
                .durable(true)
                .build();
    }

    @Bean(Queue_Work)
    public Queue Queue_Work(){
        return QueueBuilder.durable(Queue_Work).build();
    }

    /**
     *将Queue_Direct_1 绑定到交换机Exchange_direct  with
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binding_direct_work_queue(
            @Qualifier(Queue_Work) Queue queue,
            @Qualifier(Exchange_Direct_2109A) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY).noargs();
    }

}
